<?php
/* @var $this AdminPermissionController */

$this->breadcrumbs=array(
	'Admin Permission',
);
?>
<h3>Phân quyền</h3>

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'permission-form',
	'enableAjaxValidation'=>false,
	'htmlOptions'=>array('class'=>'form-horizontal'),
)); 
?>
<table class="table table-bordered table-striped permission" border="1">
	<tr class="head">
		<th>Action / Role</th>
		<?php foreach ($role as $r) {
      if($r->role != 'guest' && $r->role != 'user' && $r->role != 'receiver') {?>
		<th><?php echo $r->role?></th>
		<?php } } ?>
	</tr>
	<?php foreach ($controller as $c) {?>
	<tr class="controller">
		<td colspan="<?php echo count($role)+1?>"><?php echo $c->description?></td>
	</tr>
		<?php
			$action = AdminAction::model()->findAllByAttributes(array('controllerID'=>$c->ID,'enabled'=>1));
			foreach ($action as $a) { 
		?>
	<tr>
		<td class="action"><?php echo $a->description?></td>
			<?php foreach ($role as $item) {
        if($item->role != 'guest' && $item->role != 'user' && $item->role != 'receiver') {
				$role_per_old = AdminPermission::model()->findByAttributes(array('roleID'=>$item->ID,'actionID'=>$a->ID,'controllerID'=>$c->ID));
				if(empty($role_per_old)) {
			?>
				<td width="100px"><input type="checkbox" id="role_per_<?php echo $item->ID.'_'.$a->ID.'_'.$c->ID?>" name="role_per[]" value="<?php echo $item->ID.'_'.$a->ID.'_'.$c->ID?>"/></td>
			<?php } else { ?>
				<td width="100px"><input type="checkbox" id="role_per_<?php echo $item->ID.'_'.$a->ID.'_'.$c->ID?>" name="role_per[]" value="<?php echo $item->ID.'_'.$a->ID.'_'.$c->ID?>" checked="checked"/></td>
			<?php }
				} } ?>
	</tr>
		<?php } ?>
	<?php } ?>
</table>
<?php echo CHtml::submitButton('Cập nhật', array('class'=>'btn btn-success')); ?>
<?php $this->endWidget(); ?>